<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가

@include_once("$g4[path]/plugin/mobile/_config.php");

if (!$_GET[mobile] && $mw_mobile[m_subdomain] && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != "xmlhttprequest") {
    if (substr($_SERVER[HTTP_HOST], 0, 2) == "m." && !strstr($_SERVER[PHP_SELF], "plugin/mobile")
                                                  && !strstr($_SERVER[PHP_SELF], "plugin/bbs_shorten")
                                                  && !strstr($_SERVER[PHP_SELF], "plugin/social-login")
                                                  && !strstr($_SERVER[PHP_SELF], "skin/board/{$board['bo_skin']}")
                                                  && !strstr($_SERVER[PHP_SELF], "plugin/{$mw_mobile['attendance_dir']}")
                                                  && !strstr($_SERVER[PHP_SELF], "$g4[bbs]/zip")
                                                  && !strstr($_SERVER[PHP_SELF], "$g4[bbs]/board")
                                                  && !in_array($_SERVER[PHP_SELF], $mobile_except_page)) {
        goto_url("$g4[path]/plugin/mobile/");
    }
    // ssl 사용시 모바일 서브도메인 바로잡음
    else if ($g4[cookie_domain] && $g4[https_url]
                                && $_SERVER[HTTP_HOST] == str_replace("https://", "", $g4[https_url])
                                && strstr($_SERVER[PHP_SELF], "plugin/mobile")
                                && !strstr($_SERVER[PHP_SELF], "_check.php")
                                && !strstr($_SERVER[PHP_SELF], "_update.php")) {
        goto_url(set_http('m'.$g4[cookie_domain]).$_SERVER[REQUEST_URI]);
    }
}

if ($_GET[mobile])
    set_session("mw_is_mobile", true);

if (strstr(strtolower($_SERVER[HTTP_USER_AGENT]), "mobile") && strstr($_SERVER[PHP_SELF], "plugin/mobile"))
    set_session("mw_is_mobile", false);

if ($mw_mobile[auto_move]
    and !$_GET[mobile]
    and !get_session("mw_is_mobile")
    and strstr(strtolower($_SERVER[HTTP_USER_AGENT]), "mobile")
    and strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != "xmlhttprequest"
    and !in_array($_SERVER[PHP_SELF], $mobile_except_page)
)
{
    if (!strstr($_SERVER[PHP_SELF], "plugin/mobile") && (
           is_file("./$dbconfig_file")
        or strstr($_SERVER[PHP_SELF], "/$g4[bbs]/board.php")
    )) {
        //$url = set_http($_SERVER[HTTP_HOST]);
        $url = $g4[url];
        if ($mw_mobile[m_subdomain])
            $url = str_replace($_SERVER[HTTP_HOST], "m$g4[cookie_domain]", $url);

        $url .= "/plugin/mobile/";
        if ($bo_table)
            $url .= "board.php?bo_table=$bo_table";
        if ($wr_id)
            $url .= "&wr_id=$wr_id";

         goto_url($url);
    }
}

